// import home from "@/views/home/index.vue";
// import mine from "@/views/mine/index.vue";
// import login from "@/views/login/index.vue"; // 登录注册页面
import { createRouter, createWebHistory, createMemoryHistory } from "vue-router";

// 动态的注册路由组件 懒加载
// 修改文件名是为了打包后的生成文件是语义化的
const home = () => import("@/views/home/homeIndex.vue");
const login = () => import("@/views/login/loginIndex.vue");
const mine = () => import("@/views/mine/mineIndex.vue");
const roomDetail = () => import("@/views/detail/roomIndex.vue");

const routes = [
  {
    path: "/",
    name: "home",
    component: home,
    meta: {
      title: "爱此迎-全球大型房屋租赁平台",
      keywords: "爱此迎，特价房源，品质房源，租赁平台",
      description: "爱此迎（Airbnb）是房屋租赁平台。爱此迎（Airbnb）的房屋涉及上海、北京、杭州、苏州等60个城市，覆盖了特价房源、品质房源，帮助用户实现从线上房屋预定和浏览功能。 ",
      keepAlive: false
    }
  },
  {
    path: "/mine",
    name: "mine",
    component: mine,
    meta: {
      title: "",
      keywords: "",
      description: "",
      keepAlive: false
    }
  },
  {
    path: "/login",
    name: "login",
    component: login,
    meta: {
      title: "",
      keywords: "",
      description: "",
      keepAlive: false
    }
  },
  {
    path: "/roomDetail/:id",
    name: "roomDetail",
    component: roomDetail,
    meta: {
      title: "",
      keywords: "",
      description: "",
      keepAlive: false
    }
  }
];

export function createSSRRouter() {
  return createRouter({
    // 在客户端渲染的时候需要使用 createWebHistory(), 在服务端渲染的时候需要使用到createMemoryHistory()
    // import.meta.env.SSR 用来判断当前是否处在服务端渲染中
    history: import.meta.env.SSR ? createMemoryHistory() : createWebHistory(),
    routes,
    scrollBehavior(to, from, savedPosition): void {
      window.scroll(0, 0);
    }
  });
}
